<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.48">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #8b2618}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
span.s1 {color: #0037f0}
span.s2 {color: #0024f8}
span.s3 {color: #0032ad}
span.s4 {color: #001bb9}
span.s5 {color: #606060}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>FFTPeak<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Find peak value in an FFT frame</b></p>
<p class="p2"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span># freq, mag = FFTSlope.kr(chain)</b></p>
<p class="p2"><br></p>
<p class="p3">Given an <a href="SC://FFT"><span class="s1">FFT</span></a> <b>chain</b>, this finds the bin with the strongest magnitude. It outputs the frequency of that bin, and its magnitude.<span class="Apple-converted-space">  </span>No interpolation is done on the values.</p>
<p class="p2"><br></p>
<p class="p3">This could be used as a primitive pitch detector, but in practice autocorrelation methods (as used in <a href="SC://Pitch"><span class="s2">Pitch</span></a> and <a href="../../../../../../Library/Application Support/SuperCollider/Extensions/Nick Collins/MachineListening/MachineListening Help/Tartini.help.rtf"><span class="s2">Tartini</span></a>) give more reliable pitch tracks. This simple approach gives poor resolution and robustness for that purpose. However it can be useful for other things...</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><b>Example</b></p>
<p class="p2"><br></p>
<p class="p4">// Let's see how good it is at tracking the "pitch" of a sinewave!</p>
<p class="p5">s.boot;</p>
<p class="p5">b = <span class="s3">Buffer</span>.alloc(s,2048,1);</p>
<p class="p5">(</p>
<p class="p5">x = {</p>
<p class="p5"><span class="s4">var</span> in, chain, pitch, freq, mag;</p>
<p class="p6"><br></p>
<p class="p5">pitch = <span class="s4">MouseX</span>.kr(100, 1000, 1);</p>
<p class="p6"><br></p>
<p class="p5">in = <span class="s4">SinOsc</span>.ar(pitch);</p>
<p class="p6"><br></p>
<p class="p5">chain = <span class="s4">FFT</span>(b.bufnum, in);</p>
<p class="p6"><br></p>
<p class="p5"># freq, mag = <span class="s4">FFTPeak</span>.kr(chain);</p>
<p class="p6"><br></p>
<p class="p5"><span class="s4">Out</span>.ar(0, in.dup * 0.1);</p>
<p class="p6"><br></p>
<p class="p5">pitch.poll(label: <span class="s5">"Tru freq"</span>);</p>
<p class="p5">freq .poll(label: <span class="s5">"Inferred"</span>);</p>
<p class="p5">}.play(s);</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">x.free;</p>
<p class="p6"><br></p>
</body>
</html>
